home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
manual-p
/
vh-man2h.000
/
vh-man2h
/
vh-man2html-1.3
/
mansearch
< prev
next >
Wrap
Text File
|
1996-04-05
|
4KB
|
149 lines
#!/bin/sh
#
# Interface to a glimpse search of the man pages.
# Michael Hamilton <michael@actrix.gen.nz>
#
QUOTE="'"
export QUOTE
exec awk '
function removeopts(string) {
gsub(/^[ \t]/, "", string); # Remove leading spaces
gsub(/[ \t]$/, "", string); # Remove trailing spaces
gsub(/[ \t\\];/, ";", string); # Remove spaces before ;
gsub(/[ \t];/, ",", string); # Remove spaces before ,
# print "---" string "---" > "/dev/stderr"
while (match(string, /^-[FLBwk1-8]/)) {
if (match(string, /^-[FL]( |.)[^ \t]+[ \t]+/)) { # Option with arg
options = options " " substr(string, RSTART, RLENGTH);
string = substr(string, RSTART + RLENGTH);
}
else if (match(string, /^-[Bwk1-8][ \t]+/)) { # Option without arg
options = options " " substr(string, RSTART, RLENGTH);
string = substr(string, RSTART + RLENGTH);
}
else if (match(string, /^-[^ \t]/)) { # Remove it
string = substr(string, RSTART + RLENGTH);
}
}
return string;
}
BEGIN {
quote = ENVIRON["QUOTE"];
truncate_at = 11; # Single page display match limit.
glimpse_cmd = "glimpse -H /var/man2html -y -W -i "
for (i = 1; i < ARGC; i++) {
# print "---" i "---" ARGV[i] "---" > "/dev/stderr"
string = string " " ARGV[i];
}
# Have to be carefull to single quote this
# string later.
string = removeopts(string);
gsub(/[^a-zA-Z0-9-_+ \t\/@%;,$*|]/, " ", string);
searchdocument = "/home/httpd/html/mansearch.html";
if (!string) {
while (getline line < searchdocument) {
print line;
}
exit;
}
print "Content-type: text/html";
print "";
print "<HTML>";
print "<HEAD>";
print "<TITLE>Manual Pages - Search Results: " string "</TITLE>";
print "</HEAD>";
print "<BODY>";
print "<H1>Manual Pages - Search Results</H1>";
print "<H2>Target text: " options " " string "</H2>";
print "<A HREF=\"http:/cgi-bin/mansearch\">";
print "Perform another search";
print "</A><BR>";
print "<A HREF=\"http:/cgi-bin/man2html\">";
print "Return to Main Contents";
print "</A>";
print "<HR>";
print "<DL>";
# Unless you like being hacked, the single
# forward quotes are most important.
cmd = glimpse_cmd " " options " " quote string quote " 2>&1" ;
#print cmd > "/dev/stderr"
while (cmd | getline matchline) {
if (split(matchline, part, ":") == 1) {
continue;
}
else {
filename = part[1];
}
if (filename == "glimpse") {
print "<DT><B>"filename"</B>:";
}
else if (filename != last_filename) {
mcount++;
tcount = 0;
last_filename = filename ;
last_text = "";
match(filename, ".*/");
if (match(filename, ".*/")) {
dirname = substr(filename, 1, RLENGTH);
filename = substr(filename, RLENGTH + 1);
if (dirname != last_dirname) {
last_dirname = dirname;
print "</DL>";
print "<H3>Location: " dirname "</H3>";
print "<DL>";
}
}
if (match(filename, /\.[^.]+$/)) {
ref = substr(filename, 1, RSTART - 1) "+" substr(filename, RSTART + 1);
}
else {
ref = filename;
}
print "<DT> <a href=\"http:/cgi-bin/man2html?" ref "\">";
print filename;
print "</A>";
}
text = substr(matchline, length(filename) + 2);
tcount++;
if (tcount < truncate_at) {
sub(/^ *.[^ ]+ /, "", text);
sub(/ +$/, "", text);
gsub(/\\f./, "", text);
gsub(/\\&/, "", text);
gsub(/\\/, "", text);
print "<DD>" text;
}
else if (tcount == truncate_at) {
print "<DD> <I>...additional matches not shown.</I>";
}
}
print "</DL>";
if (mcount == 0) {
print "No matches found.";
}
else {
print "<HR>\n<P>" mcount " matches found."
}
print "</BODY>";
print "</HTML>";
exit;
}' "$@"